﻿using System;
using System.Collections.Generic;

namespace com.fukefu.tools
{
    public static class RandomPicture
    {
        private static List<string> pic;
        private static int len = 0;
        private static Random random = new Random();

        static RandomPicture()
        {
            pic = MyFunction.GetFileInfoes(Config.Pic_path);
            //过滤非图片文件
            for (int i = pic.Count - 1; i >= 0; i--)
            {
                if (!pic[i].ToLower().EndsWith("jpg"))
                {
                    pic.RemoveAt(i);
                }
            }
            len = pic.Count;
        }
        //获取一张图片
        public static string Get()
        {
            if (pic.Count == 0)
            {
                return "";
            }
            return pic[random.Next(len)];
        }
    }
}
